package com.zkzx.company.api.controller.order;

import com.zkzx.common.exception.BaseException;
import com.zkzx.common.freight.command.OrderCommand;
import com.zkzx.common.freight.model.OrderListVO;
import com.zkzx.common.freight.model.OrderVO;
import com.zkzx.common.freight.param.OrderFilterParam;
import com.zkzx.common.vo.PageResult;
import com.zkzx.common.vo.RequestFilterParams;
import com.zkzx.common.vo.StatusVO;
import com.zkzx.company.api.controller.BaseController;
import com.zkzx.company.api.service.order.OrderService;
import com.zkzx.util.json.JSONResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 北京中科智兴物联科技有限公司 @版权所有
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/12/20:40
 * @Description: 订单管理
 */
@RestController
@Validated
@Api( tags="订单管理")
@RequestMapping(value = "/orders")
public class OrderController extends BaseController {


    @Autowired
    private OrderService orderService;

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取订单列表", notes = "获取订单列表")
    public PageResult<OrderListVO> find(@ApiParam(value = "查询参数") OrderFilterParam filterParam,
                                        @ApiParam(value = "分页查询参数") RequestFilterParams params)  {

        return orderService.find(filterParam,params,super.getUserId(),super.getCompanyId());
    }

    @GetMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取订单详细", notes = "获取订单详细")
    public OrderVO getById(@PathVariable("id") Integer id) {
        //司机信息留到API接口去做
        return orderService.getById(id,super.getUserId(),super.getCompanyId());
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation(value = "新增运单信息", notes = "新增运单信息")
    public StatusVO add(@RequestBody @Valid OrderCommand command) throws BaseException {
        //留存比例要查一遍
        return orderService.add(command,super.getUserId(),super.getCompanyId());
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "修改订单信息", notes = "修改订单信息")
    public void update(@PathVariable("id") Integer id,@RequestBody @Valid OrderCommand command) {
        orderService.update(id,command,super.getUserId(),super.getCompanyId());
    }

    @PostMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "提交", notes = "提交")
    public void verification(@PathVariable("id") Integer id) {
        orderService.verification(id,super.getUserId(),super.getCompanyId());
    }

    @PostMapping("/{id}/pay")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "支付", notes = "支付")
    public void payment(@PathVariable("id") Integer id) {
        //支付
    }

    @PostMapping("/{id}/invoice")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "申请开票", notes = "申请开票")
    public void invoice(@PathVariable("id") Integer id){
        //申请开票
    }


}
